package com.hsy.dormmanage.controller;

import com.hsy.dormmanage.common.result.Constants;
import com.hsy.dormmanage.common.result.Result;
import com.hsy.dormmanage.common.result.ResultCodeEnum;
import com.hsy.dormmanage.model.Register;
import com.hsy.dormmanage.model.Student;
import com.hsy.dormmanage.model.vo.RegisterVO;
import com.hsy.dormmanage.service.CheckSer;
import com.hsy.dormmanage.service.StudentSer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 包名:com.hsy.dormmanage.controller
 * 用户:86182
 * 时间:20211110:492021/11/9
 */
@Api(value = "学生功能模块")
@RestController
@RequestMapping("/dorm/students")
public class StudentController {

    @Autowired
    private StudentSer studentSer;

    @Autowired
    private CheckSer checkSer;

    //打卡
    @ApiOperation(value = "打卡功能")
    @PostMapping("/checkin")
    public Result checkIn(HttpServletRequest request,@RequestBody RegisterVO registerVO){

        Object attribute = request.getSession().getAttribute(Constants.LOGIN_USER);
        Student student = (Student) attribute;
        //System.out.println(student);
        if (student.getIsCheck()==1){
            return Result.build(205,"不能重复打卡");
        }
        student.setIsCheck(1);
        //设置打卡
        float bodyTem = registerVO.getBodyTem();
        String location = registerVO.getLocation();

        Register register = new Register(student.getId(),student.getDormId(),student.getIsCheck(),location,bodyTem);

        checkSer.save(register);
        studentSer.updateById(student);
        return Result.ok();
    }
}
